package com.wyh.onlyoffice.controller;

import com.wyh.onlyoffice.dto.ChangeUrl;
import com.wyh.onlyoffice.service.IndexService;
import com.wyh.onlyoffice.vo.HistoryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin(origins = "*")
public class IndexController {


    private final IndexService indexService;

    public IndexController(IndexService indexService) {
        this.indexService = indexService;
    }

    @GetMapping("")
    public String index(){
        return "hello world";
    }


    @GetMapping("/init")
    public String init(){
        return indexService.insert()?"success":"fail";
    }

    @GetMapping("/history")
    public List<HistoryVo> history(){
        return indexService.history();
    }

    @GetMapping("/changes")
    public ChangeUrl changeUrls(String version){
        return indexService.changeUrls(version);
    }
}
